<template>
  <div class="import-button">
    <el-upload
      ref="elUpload"
      :multiple="false"
      :show-file-list="false"
      :http-request="uploadFileMethod"
      :before-upload="beforeProp ? beforePropFunc : beforeUpload"
      :disabled="isDisabled"
      :accept="accept"
      action
      class="file-uploader"
    >
      <div v-if="isDiy" >
        <slot />
      </div>
      <template v-else>
        <el-tooltip v-if="isIconType" :content="tooltipContent" class="item" popper-class="imprt-tooltip" effect="dark" placement="top">
          <el-button :loading="loading" type="text" size="small" class="btn-operate btn-import" >
            <img src="../../assets/import.png" style="width: 16px;height:16px;" alt="导入订单">
          </el-button>
        </el-tooltip>
        <el-button v-else :loading="loading" size="small" class="more-button" >
          {{ tooltipContent }}
        </el-button>
      </template>
    </el-upload>
  </div>
</template>
<script>
import ImportList from '@/mixins/importList';
import ImportIcon from '@/assets/medium/import.png';

export default {
  name: 'ImportButton',
  mixins: [ImportList],
  props: {
    accept: {
      type: String,
      default: '.xls,.xlsx'
    },
    // 控制是否显示成功和失败提示框
    hideConfirm: {
      type: Boolean,
      default: false
    },
    // 是否可以点击
    isDisabled: {
      type: Boolean,
      default: false
    },
    // 默认样式
    isIconType: {
      type: Boolean,
      default: true
    },
    importApi: {
      type: String,
      default: () => {
        return '';
      }
    },
    tooltipContent: {
      type: String,
      default: () => {
        return '导入';
      }
    },
    getList: { // 导入后列表刷新的方法
      type: Function,
      default: null
    },
    extendParams: {
      type: Object,
      default: null
    },
    isDiy: {
      type: Boolean,
      default: false
    },
    beforeProp: { // 上传文件之前的钩子是否使用prop传入
      type: Boolean,
      default: false
    },
    beforePropFunc: { // 手动传入的上传文件之前的钩子
      type: Function,
      default: () => {}
    },
    fileSize: { // 文件大小,当有上传钩子时传入
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      ImportIcon,
      limitNum: false
    };
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
.import-button {
  .btn-import {
    position: relative;
    padding: 0;
    .progress-text {
      display: inline-block;
      height: 22px;
      position: absolute;
      left: -36px;
      top: 4px;
    }
    // .el-icon-loading {
    //   position: absolute;
    //   top: 9px;
    //   left: -12px;
    // }
    img {
      width: 19px;
      height: 18px;
    }
  }
  .file-uploader {
    .el-upload {
      width: 100%;
    }
  }
}

.medium-import-btn {
  font-size: 12px;
  color: #333333;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  height: 30px;
  background-color: #ffffff;
  border-radius: 50px 50px 50px 50px;
  border: solid 1px #e5e5e5;
  margin-left: 10px;
  font-weight: normal;
  cursor: pointer;
  &.hover:hover {
    color: #6e8fa2;
    border-color: #e5e5e5;
    background-color: #ffffff;
  }
  img {
    width: 13px;
    height: 12px;
    margin-right: 5px;
  }
   &.dropdown-menu {
    background-color: rgba(255, 255, 255, 0.0);
    color: #606266;
    &.hover:hover {
      color: #406EFF;
      background-color: rgba(255, 255, 255, 0.0);
    }
  }
}
.imprt-tooltip {
  padding: 5px 10px;
}
.more-button {
  padding: 0 8px;
  height: 32px;
  border: 1px solid #DDDDDD;
  border-radius: 4px;
  color: #666666;
  background: #fff;
}
</style>
